var http = require('http');
var fs = require('fs');
var path = require('path');

http.createServer((req,res)=>{
    if (!process.argv[2]) {
        var tempPath = __filename;

        fs.access(tempPath,fs.constants.F_OK,(err)=>{
            if (err) {
                console.log(error);
            } else {
                var readStream = fs.createReadStream(tempPath);
                res.writeHead(200,{"content-Type":"text/html;charset=utf-8"});
                readStream.pipe(res);
            }
        })
    }
    else{
        var fname = process.argv[2];
        var tempPath = path.join(__dirname,fname);

        
        fs.access(tempPath,fs.constants.F_OK,(err)=>{
            if (err) {
                console.log(error);
            } else {
                var readStream = fs.createReadStream(tempPath);
                res.writeHead(200,{"content-Type":"text/html;charset=utf-8"});
                readStream.pipe(res);
            }
        })
            
            
        
    }
}).listen(8081);
console.log('Server is listening 8081');